﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Net;
using System.IO;

namespace wljHomoWork2WS
{
    public abstract class AwljWS:IwljWS2
    {
        public abstract XmlDocument _XmlDoc
        {
            get;
        }
        /// <summary>
        /// 返回Xml节点集，ElementName不带命名空间
        /// </summary>
        /// <param name="ElementName">节点名称的Xpath表达式（不带命名空间）</param>
        /// <returns></returns>
        public virtual XmlNodeList ReturnNodesByElement(string ElementName)
        {
            try
            {
                XmlNodeList Nodes = _XmlDoc.SelectNodes(ElementName);
                return Nodes;
            }
            catch (Exception Ex)
            {
                throw new Exception(Ex.Message);
            }
        }
        /// <summary>
        /// 返回Xml节点集，ElementName带有命名空间
        /// </summary>
        /// <param name="ElementName">节点名称的Xpath表达式（带有命名空间）</param>
        /// <param name="_NameSpaceManager">命名空间管理器</param>
        /// <returns></returns>
        public virtual XmlNodeList ReturnNodesByElement(string ElementName, XmlNamespaceManager _NameSpaceManager)
        {
            try
            {
                XmlNodeList Nodes = _XmlDoc.SelectNodes(ElementName,_NameSpaceManager);
                return Nodes;
            }
            catch (Exception Ex)
            {
                throw new Exception(Ex.Message);
            }
        }
        /// <summary>
        /// 返回Xml节点集，ElementName带有命名空间
        /// </summary>
        /// <param name="ElementName">节点名称的Xpath表达式（带有命名空间)</param>
        /// <param name="NameSpaceValue">命名空间名字</param>
        /// <param name="NameSpaceUri">命名空间uri</param>
        /// <returns></returns>
        public virtual XmlNodeList ReturnNodesByElement(string ElementName, string NameSpaceValue, string NameSpaceUri)
        {
            XmlNamespaceManager _XmlNamespaceManager = new XmlNamespaceManager(_XmlDoc.NameTable);
            _XmlNamespaceManager.AddNamespace(NameSpaceValue, NameSpaceUri);
            try
            {
                XmlNodeList Nodes = _XmlDoc.SelectNodes(ElementName, _XmlNamespaceManager);
                return Nodes;
            }
            catch (Exception Ex)
            {
                throw new Exception(Ex.Message);
            }
        }
    }
}
